package com.myapplication.ui.listfragment;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.myapplication.R;
import com.myapplication.bean.ListBean;

import java.util.List;

/**
 * Created by My on 2016/10/13.
 */
public class ListFragmentAdapter extends BaseAdapter {
    private Context context;
    private List<ListBean.DataBean> listBeanList;

    public void setListFragmentAdapter(List<ListBean.DataBean> listBeanList){
        this.listBeanList=listBeanList;
    }

    public ListFragmentAdapter(Context context,List<ListBean.DataBean> listBeanList){
        this.context=context;
        this.listBeanList=listBeanList;
//        Log.d("tag", "ListFragmentAdapter: "+listBeanList.size());
    }

    @Override
    public int getCount() {
        return listBeanList.size();
    }

    @Override
    public Object getItem(int i) {
        return listBeanList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    ViewHolder holder;
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Log.d("ListFragmentAdapter", "getView: "+listBeanList.size());
        holder=new ViewHolder();
        if(view==null){
            view= LayoutInflater.from(context).inflate(R.layout.item_lv_list,null);
            holder.iv_list_big= (ImageView) view.findViewById(R.id.iv_big_list);
            holder.rv = (RecyclerView) view.findViewById(R.id.recycleview_small_list);
            view.setTag(holder);
        }else{
            holder= (ViewHolder) view.getTag();
        }
        String BigImageUrl=listBeanList.get(i).getImageUrl();
//        String SmallImageUrl=list.get(i).getItems().get(i).getImageUrl();
        Glide.with(context).load(BigImageUrl).into(holder.iv_list_big);

        ListRecycleViewAdapter adapter = new ListRecycleViewAdapter(context, listBeanList.get(i).getItems());
        holder.rv.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
        holder.rv.setAdapter(adapter);
        return view;
    }
    static class ViewHolder{
        ImageView iv_list_big;
        RecyclerView rv;
    }
}
